using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Management;

namespace GameXNA_Master
{
    interface Menu
    {

        event Action iMoveDown_Menu;
        event Action iMoveUp_Menu;
        event Action iMoveLeft_Menu;
        event Action iMoveRight_Menu;
        event Action iConfirm_Menu;

        void MoveUp();
        void MoveDown();
        void MoveLeft();
        void MoveRight();
        void ConfirmAction();

        void Update(GameTime gameTime, out int SelectedMenu);

        void Draw(SpriteBatch spriteBatch);
    }

    public class MenuHandler : Microsoft.Xna.Framework.DrawableGameComponent
    {
        Menu[] menus;
        SpriteBatch spriteBatch;

        public void MoveSelectUp()
        {
            menus[selectedMenu].MoveUp();
        }
        public void MoveSelectDown()
        {
            menus[selectedMenu].MoveDown();
        }
        public void MoveSelectRight()
        {
            menus[selectedMenu].MoveRight();
        }
        public void MoveSelectLeft()
        {
            menus[selectedMenu].MoveLeft();
        }
        public void Confirm()
        {
            menus[selectedMenu].ConfirmAction();
        }



        public MenuHandler(Game game)
            : base(game)
        {
            Game.Services.AddService(typeof(MenuHandler), this);
        }


        public override void Initialize()
        {

            spriteBatch = new SpriteBatch(Game.GraphicsDevice);


            base.Initialize();
        }


        protected override void LoadContent()
        {
            menus = new Menu[] { new MainMenu(Game), new OptionMenu(Game), new TutorialMenu(Game) };
            base.LoadContent();
        }

        int selectedMenu = 0;

        public override void Update(GameTime gameTime)
        {
            menus[selectedMenu].Update(gameTime, out selectedMenu);

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            menus[selectedMenu].Draw(spriteBatch);

            base.Draw(gameTime);

        }


    }
}